import pandas as pd

# 读取Excel文件
input_file = 'output\project_weekly_reports.xlsx'
df = pd.read_excel(input_file)

# 遍历每一行，处理偶数id的sub_title
for index, row in df.iterrows():
    if row['id'] % 2 == 0:
        # 找到id为当前id-1的行
        target_row_index = df[df['id'] == row['id'] - 1].index
        if not target_row_index.empty:
            target_row_index = target_row_index[0]
            # 将sub_title的内容转移到target_row的main_title列
            df.at[target_row_index, 'main_title'] = row['sub_title']

# 删除id为偶数的行
df = df[df['id'] % 2 != 0]

# 重置索引
df = df.reset_index(drop=True)

# 保存修改后的DataFrame回Excel文件
output_file = 'your_output_file.xlsx'
df.to_excel(output_file, index=False)

print(f"数据已保存到 {output_file}")